<?php
/**
 * 异议申诉处理控制器
 * @author Jackie Yang
 *
 */
class ctrl_complaints extends ctrl_base
{
    public static function index() {
    	//获取open_id 走用户体系取 user_id
    	if(empty($_SESSION['wx_userinfo']['openid'])) {
    		setcookie('backurl',HOST_URL.'/?'.$_SERVER['QUERY_STRING'],0);
    		ctrl_weixin::oauth();
    	}else{
    		setcookie('backurl','');
    		unset($_SESSION['backurl']);
    	}
    	$openid = $_SESSION['wx_userinfo']['openid'];
    	$data = model_user::get_user_by_openid($openid,WEIXINHAO);
    	if(isset($data['user_id']) && $data['user_id'] != '0') {
    		self::smarty() -> assign('user_id',$data['user_id']);
    	} else {
    		$reg_url = HOST_URL.'/index.php?act=register';
    		$msg = "  您好！您还未进行用户注册，不能享受此服务,请点击<a href='".$reg_url."'>这里</a>注册。";
    		model_send::send_text($openid,$msg);
    	}
    	self::smarty() -> display('complaints.html');
    }
    
    public static function saveUserDiscrepancy() {
    	//获取open_id 走用户体系取 user_id
    	if(empty($_SESSION['wx_userinfo']['openid'])) {
    		setcookie('backurl',HOST_URL.'/?'.$_SERVER['QUERY_STRING'],0);
    		ctrl_weixin::oauth();
    	}else{
    		setcookie('backurl','');
    		unset($_SESSION['backurl']);
    	}
    	$data = array();
    	$data['User_ID'] = $_SESSION['wx_userinfo']['openid'];
    	$data['Product_Type'] = trim($_POST['Product_Type']);
    	$data['Product_Contract'] = trim($_POST['Product_Contract']);
    	$data['Product_Spec'] = trim($_POST['Product_Spec']);
    	$data['Product_Grade'] = trim($_POST['Product_Grade']);
    	$data['Problem_Batch'] = trim($_POST['Problem_Batch']);
    	$data['Qty_Product'] = trim($_POST['Qty_Product']);
    	$data['Qty_Product_Semi'] = trim($_POST['Qty_Product_Semi']);
    	$data['Qty_Product_Parent'] = trim($_POST['Qty_Product_Parent']);
    	
    	$data['Defect_Type'] = trim($_POST['Defect_Type']);
    	$data['Defect_Description'] = trim($_POST['Defect_Description']);
    	$data['Loss_Description'] = trim($_POST['Loss_Description']);
    	$data['Loss_Money'] = trim($_POST['Loss_Money']);    	
    	$data['Loss_Calculate'] = trim($_POST['Loss_Calculate']);
    	
    	$data['Confirm_Addr'] = trim($_POST['Confirm_Addr']);
    	$data['Confirm_Person'] = trim($_POST['Confirm_Person']);
    	$data['Confirm_Mobile'] = $_POST['Confirm_Mobile'];
    	$data['Confirm_Appoint_Time'] = trim($_POST['Confirm_Appoint_Time']);
    	
    	framework_static_function::write_log('用户提交的数据:'.json_encode($data),'weixin_complaints');
    	$result = model_complaints::add_recode($data);
    	if ($result != 0) { //处理成功
			self::smarty ()->assign ( "result_class", 'icon67_status' );
			self::smarty ()->assign ( "errMsg", '恭喜您，提交成功！' );
			self::smarty ()->assign ( "comment", '我们将在1个工作日内回复您' );
			self::smarty ()->display ( 'show_result.html' );
			exit ();
		} else {
			self::smarty ()->assign ( "result_class", 'icon67_status warn' );
			self::smarty ()->assign ( "errMsg", '对不起，数据提交失败！' );
			self::smarty ()->assign ( "comment", '系统出现故障，请稍后重试' );
			self::smarty ()->display ( 'show_result.html' );
			exit ();
		}
    	    	
    	/*$url = SAVE_USER_DISCREPANCY_URL;
    	$postData['Data'] = json_encode($data);
    	$res = model_weixin::http_post($url,$postData);
    	framework_static_function::write_log('用户提交的数据:'.json_encode($postData),'weixin_complaints');
    	framework_static_function::write_log('接口返回:'.$res,'weixin_complaints');
    	if($res != false) {
    		$result = json_decode($res,true);
    		if($result['2_Status'] == 1) { //处理成功
    			self::smarty()->assign("result_class",'icon67_status');
				self::smarty()->assign("errMsg",'恭喜您，提交成功！');
				self::smarty()->assign("comment",'我们将在1个工作日内回复您');
				self::smarty()->display('show_result.html');
				exit;
			} else {
    			self::smarty()->assign("result_class",'icon67_status warn');
    			self::smarty()->assign("errMsg",$result['3_Msg']);
    			self::smarty()->display('show_result.html');
    			exit;
    		}
    	} else {
    		self::smarty()->display('error/wx_error.html'); exit;
    	}*/
    }
}
